<?php
namespace Admin\Controller;

//偏远地区附加费管理
class RemoteAreaController extends BaseController{


    function _initialize() {
        parent::_initialize ();
    }


    //管理列表
    public function index(){


        $this->assign("page_title","偏远地区附加费管理列表");
        $this->display();
    }

    public function index_list(){
        //排序
        $_sort = I('request._sort',' ASC ','trim');
        //排序字段
        $_sort_column = I('request._sort_column',' region_id ','trim');
        $this->assign('_sort',$_sort);
        $this->assign('_sort_column',$_sort_column);

        $where['is_delete'] = 0;
        $where['is_general'] = 1;//is_general=1的才显示
        $stringwhere=' ems_money !=0 ';

        $_listrows = I('request._listrows', 20, 'intval');
        $stringwhere  = ltrim(trim($stringwhere),'and');
        if(!empty($stringwhere)){
            $where['_string']=$stringwhere;
        }

        $_where_order_field["where"] = $where;
        $_where_order_field['order']=$_sort_column.' '.$_sort;
        $_where_order_field['listrows'] = $_listrows;
        $_where_order_field["id"]="load_tb_div";
        $_where_order_field['alias']="g";
        $region_list = $this->_getListsFromModel('region',$_where_order_field);
        $this->assign('_datalist',$region_list);
        $this->display();
    }

    //删除
    public function deleteaa(){
        $region_id=I('request.region_id');
        $data['ems_money']=0;
        $z=M('region')->where(array('region_id'=>$region_id))->save($data);
        if($z!==false){
            $exe_scriptstr="<script>var parent=    art.dialog.opener;
                        parent.loadaa();
                        setTimeout(function(){
                            art.dialog.close();
                        },1200);
                        </script>";
            $this->success('删除成功'.$exe_scriptstr);
        }else{
            $this->error('删除失败');
        }
    }

    //添加
    public function add(){
        $listname=M('region')->where(array('parent_id'=>1))->select();
        $this->assign('listname',$listname);
        $this->display();
    }

    //修改
    public function update(){
        $region_id=I('request.region_id');
        $list=M('region')->where(array('region_id'=>$region_id))->find();
        $this->assign('list',$list);
        $this->display('add');
    }

    //添加修改之后的操作
    public function addorupdate(){
        $region_id=I('request.region_id');
        $data['ems_money']=I('request.ems_money');
        $a=true;
        if(!empty($region_id)){//修改
            $a=true;
            $z=M('region')->where(array('region_id'=>$region_id))->save($data);
        }else{//添加
            $a=false;
            $region_id=I('request.region_name');
            if($data['ems_money']){//附加费用不为0
                $z=M('region')->where(array('region_id'=>$region_id))->save($data);
            }else{
                $this->error('添加时附加费用不能为0');
            }
        }
        if($z!==false){
            $exe_scriptstr="<script>var parent=    art.dialog.opener;
                        parent.loadaa();
                        setTimeout(function(){
                            art.dialog.close();
                        },1200);
                        </script>";
            if($a) {
                $this->success('编辑成功' . $exe_scriptstr);
            }else{
                $this->success('添加成功'.$exe_scriptstr);
            }
        }else{
            $this->error('编辑失败');
        }
    }
}
?>